package com.jy.wms.controller;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.WmsGoodsAlarm;
import com.jy.wms.service.WmsGoodsAlarmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ClassName: WmsGoodsAlarmController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author Liyi
 * @Date Mon Dec 25 14:54:44 CST 2017
 */
@RestController
@RequestMapping("/wmsGoodsAlarm")
@Api(value = "/wmsGoodsAlarm", description = "关于货品预警操作")
public class  WmsGoodsAlarmController extends BaseController<WmsGoodsAlarmService,WmsGoodsAlarm> {


    @GetMapping(value = "/list")
    @ApiOperation(value = "货品预警",response = JSONObject.class, notes = "货品预警列表")
    public @ResponseBody JSONObject list(HttpSession session) {
        JSONObject json = getJSONObject();
        try {
            UserInfo userinfo= (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
            List<WmsGoodsAlarm> list =  baseService.getList(String.valueOf(userinfo.getUser().getOrgId().get(0)));
            json = SetStatus.setSearchType(JSONArray.fromObject(list).toString(),list.size());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }

    @PostMapping(value = "/editYjzt")
    @ApiOperation(value = "货品预警",response = JSONObject.class, notes = "批量修改货品预警信息的预警状态")
    public @ResponseBody JSONObject editYjzt(@RequestBody SetAndModifyModel setAndModifyModel, HttpSession session) {
        JSONObject json = getJSONObject();
        try {
            baseService.editYjzt(setAndModifyModel.getIds());
        } catch (SucessException e) {
            json = SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"批量修改货品预警信息的预警状态成功","","");
        } catch (ServiceException e) {
            json = SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"批量修改货品预警信息的预警状态失败",e.getMessage(),"");
        } catch (Exception e){
            json = SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"批量修改货品预警信息的预警状态失败",e.getMessage(),"");
        }
        return json;
    }

    @PostMapping(value = "/del")
    @ApiOperation(value = "货品预警",response = JSONObject.class, notes = "批量删除货品预警信息")
    public @ResponseBody JSONObject del(@RequestBody SetAndModifyModel setAndModifyModel, HttpSession session) {
        JSONObject json = getJSONObject();
        try {
            baseService.del(setAndModifyModel.getIds());
        } catch (SucessException e) {
            json = SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"批量删除货品预警信息成功","","");
        } catch (ServiceException e) {
            json = SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"批量删除货品预警信息失败",e.getMessage(),"");
        } catch (Exception e){
            json = SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"批量删除货品预警信息失败",e.getMessage(),"");
        }
        return json;
    }

}
